package com.example.whm;



import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.holoeverywhere.LayoutInflater;
import org.holoeverywhere.app.Activity;
import org.holoeverywhere.app.AlertDialog;
import org.holoeverywhere.app.Application;
import org.holoeverywhere.app.Dialog;
import org.holoeverywhere.app.Fragment;
import org.holoeverywhere.app.ProgressDialog;
import org.holoeverywhere.preference.SharedPreferences;
import org.holoeverywhere.widget.AdapterView;
import org.holoeverywhere.widget.AdapterView.OnItemSelectedListener;
import org.holoeverywhere.widget.ArrayAdapter;
import org.holoeverywhere.widget.CheckBox;
import org.holoeverywhere.widget.ListPopupWindow;
import org.holoeverywhere.widget.ListView;
import org.holoeverywhere.widget.Spinner;
import org.holoeverywhere.widget.TextView;
import org.holoeverywhere.widget.Toast;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioGroup;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
import com.example.whm.lib.box_Selection;
import com.example.whm.model.Address;
import com.example.whm.model.Box;


public class FourFragmentOrder extends Fragment implements OnItemSelectedListener,OnClickListener{

	private AQuery aq; 
	private AQuery aq2;
	
	private String topic;
	Address add;
	List<Box> boxs;
	int num=0;
	int price=0;
	int tag;
	box_Selection mCallback;
	Spinner sp;
	ListPopupWindow popup;
	
	RadioGroup radioButtonGroup;
	ProgressDialog dialog;
	adapter adap;
	adapter2 adap2;
	TextView num_t;
	TextView price_t;
	List<CheckBox> check_list=new ArrayList<CheckBox>();
	
    @Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
    	View view = inflater.inflate(R.layout.four_layout_item, container, false); 
    	aq=new AQuery(getActivity());
    	aq2=new AQuery(getActivity(), view);
    	
    	return view;
	}






	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		init();
		
	}

	 AQuery a;
	ListView list;
public void init(){
	
	  String url="http://"+Whm_app.api_url+":9000/api/buy_box?tag=1";
	  AjaxCallback<String> cb = new AjaxCallback<String>();        
	  cb.url(url).type(String.class).weakHandler(this, "ui");
	  SharedPreferences sp=((Application)getActivity().getApplication()).getSharedPreferences("whm",Context.MODE_PRIVATE);
  	String cookiename=sp.getString("cookie_name",null);
  	String cookievalue=sp.getString("cookie_value",null);
  	if (cookiename!=null&&cookievalue!=null) {
  		cb.cookie(cookiename,cookievalue);               
	}
	  aq.ajax(cb);
  }

  public void ui(String url, String r, AjaxStatus status){
	
	  System.out.println("ui  s="+r); 
	  if (status.getCode()==200) {
		 
		  
		  final String s=r;
		  new Thread( new Runnable() {
			  @Override
			public void run() {
				  // String s1= JSON.parseObject(s).getString("users");
				  
				  String addj= JSON.parseObject(s).getString("add");
				  String listj= JSON.parseObject(s).getString("list");
				  add= JSON.parseObject(addj, Address.class);
				  boxs= JSON.parseArray(listj, Box.class);
				  System.out.println("boxs.size()========="+boxs.size());
				  if (list!=null) {
					  num=0;
					  price=0;
				  }
				  for(Box b:boxs){
					  num=num+b.getNum();
					  price=price+b.getPrice();
					  
				  };
				  
				  getActivity().runOnUiThread(new Runnable() {
					  
					  @Override
					  public void run() {
						
						  if (list!=null) {
							  show_dialog(false);
							  Whm_app.newl.remove(Integer.valueOf(1));
							  num_t.setText(String.valueOf(num));
							  price_t.setText(String.valueOf(price));
							  List<List<Box>> l= new ArrayList<List<Box>>();
							  l.add(boxs);
							  adap.setList(l);
							  adap.notifyDataSetChanged();
						}else{		
						  
						  aq2.id(R.id.four_layout_progress).gone();
						  aq2.id(R.id.four_layout_line).visible();
						  
						   list=(ListView) aq2.id(R.id.four_layout_detail_listview).getListView();
						  View v=getActivity().getLayoutInflater().inflate(R.layout.four_layout_header, null);
						  View v2=getActivity().getLayoutInflater().inflate(R.layout.four_layout_footer, null);
						    a=new AQuery(v);
						  AQuery a2=new AQuery(v2);
						  a.id(R.id.four_layout_contact_name).text(add.getContact_name());
						  a.id(R.id.four_layout_contact_phone).text(add.getPhone());
						  a.id(R.id.four_layout_contact_addr).text(add.getDetail_address());
						  a.id(R.id.four_layout_address_select).clicked(FourFragmentOrder.this); 
						  
						  a2.find(R.id.four_layout_btn_sure).clicked(FourFragmentOrder.this); 
						   radioButtonGroup=(RadioGroup) a.find(R.id.four_layout_pay).getView();
						  list.addHeaderView(v);
						  list.addFooterView(v2);
						  List<List<Box>> l= new ArrayList<List<Box>>();
						  l.add(boxs);
						  adap=new adapter(l);
						  aq2.id(R.id.four_layout_detail_listview).adapter(adap);
						}
						  //Utility.setListViewHeightBasedOnChildren(list);
					  }
				  });
			  }
		  }).start();
			
		  
	}else{
		Toast.makeText(getActivity(), "request error", 1000).show();
		
	}
	  
  }

  
  
  
  
  
  
  
  class adapter extends BaseAdapter{

		
		List<List<Box>> list;
		public adapter() {
			super();
			// TODO Auto-generated constructor stub
		}
	   
		
		
		public List<List<Box>> getList() {
			return list;
		}



		public void setList(List<List<Box>> list) {
			this.list = list;
		}



		public adapter(List<List<Box>> list) {
			super();
			this.list = list;
		}


		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return list.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			// TODO Auto-generated method stub
		
			System.out.println("arg0---------------"+arg0);
			if(arg1 == null){
				arg1 = aq.inflate(arg1, R.layout.four_layout_list, arg2);
			}
			
			
			List<Box> i = (List<Box>) getItem(arg0);
			AQuery aq = aq2.recycle(arg1);
		    adap2=new adapter2(i);
			aq.id(R.id.four_layout_list_item_listview).adapter(adap2);
			aq.id(R.id.four_layout_btn_all).clicked(FourFragmentOrder.this);
			aq.id(R.id.four_layout_btn_del).clicked(FourFragmentOrder.this);
			
		   // sp=(Spinner) aq.id(R.id.four_layout_list_spinner).getView();				
		//	sp.setSelection(0, true);
			//sp.setOnItemSelectedListener(FourFragmentOrder.this); 
			 /*v=(TextView) aq.id(R.id.four_layout_text_sp).getTextView();
			v.setText("order");
			v.setOnClickListener(FourFragmentOrder.this);*/
			//showListPopup(v);
		     num_t = (TextView) aq.id(R.id.four_listview_footview_num).getTextView();
			 num_t.setText(String.valueOf(num));
			 price_t = (TextView) aq.id(R.id.four_listview_footview_price).getTextView();
			 price_t.setText(String.valueOf(price));
			
		    aq.id(R.id.four_listview_footview_num).text(String.valueOf(num));
		    aq.id(R.id.four_listview_footview_price).text(String.valueOf(price));
			
			return arg1;
		}
		
		
	}
  
 
  public void showListPopup(View anchor) {
      popup = new ListPopupWindow(getActivity());
      popup.setAnchorView(anchor);
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_2);  
      adapter.add("order");  
      adapter.add("preorder");  
      adapter.add("subscribe");    
      popup.setAdapter(adapter);
      ListView list=popup.getListView();
      
  //    popup.setWidth(300);
   //   popup.setHeight(400);
    // list.setOnItemSelectedListener();
      //list.setOnItemClickListener(FourFragmentOrder.this);
      //.setOnItemClickListener(FourFragmentOrder.this);
      
  }
  
  
  public void makeMenu(Menu menu, MenuInflater inflater) {
      if (menu instanceof ContextMenu) {
          ((ContextMenu) menu).setHeaderTitle("Context menu title");
      }
      menu.clear();
      inflater.inflate(R.menu.menu, menu);
      for (int i = 0; i < menu.size(); i++) {
          menu.getItem(i).setOnMenuItemClickListener(mOnMenuItemClickListener);
      }
     
  }
  
  private final OnMenuItemClickListener mOnMenuItemClickListener = new OnMenuItemClickListener() {
      @Override
      public boolean onMenuItemClick(MenuItem menuItem) {
          boolean result = false;
          final int id = menuItem.getItemId();
          if (menuItem.getTitle().equals("order")) {
        	  mCallback.show_boxf(0);
		  }
          if (menuItem.getTitle().equals("preorder")) {       
        	  mCallback.show_boxf(1);
          }
          if (menuItem.getTitle().equals("subscribe")) {        	  
        	  mCallback.show_boxf(2);
          }
          //  System.out.println("onMenuItemClick id========="+id);
          return true;
      }
  };
  
  class adapter2 extends BaseAdapter{

		
		List<Box> list;
		public adapter2() {
			super();
			// TODO Auto-generated constructor stub
		}
	   
		
		
		public List<Box> getList() {
			return list;
		}



		public void setList(List<Box> list) {
			this.list = list;
		}



		public adapter2(List<Box> list) {
			super();
			this.list = list;
		}


		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return list.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			// TODO Auto-generated method stub
		
			System.out.println("arg0---------------"+arg0);
			if(arg1 == null){
				arg1 = aq.inflate(arg1, R.layout.four_layout_list_item, arg2);
			}
			
			
			Box i = (Box) getItem(arg0);
			AQuery aq = aq2.recycle(arg1);
		    aq.id(R.id.four_layout_list_item_name).text(i.getEntity().getName());
		    aq.id(R.id.four_layout_list_item_price).text("￥"+i.getEntity().getPrice());
		    aq.id(R.id.four_layout_list_item_num).text(String.valueOf(i.getNum()));
		    aq.id(R.id.four_layout_list_item_tatalprice).text(String.valueOf(i.getPrice()));
		    CheckBox checkb = (CheckBox) aq.id(R.id.four_layout_list_item_check).getCheckBox();
		    checkb.setOnClickListener(FourFragmentOrder.this); 
		  //  checkb.setOnCheckedChangeListener(FourFragmentPreorder.this);
		    checkb.setTag(arg0);
		    if (!check_list.contains(checkb)) {
				check_list.add(checkb);
			}
		    
		    
		    
			String tbUrl = i.getEntity().getPre_pic().replace("localhost", Whm_app.api_url);		
			if(aq.shouldDelay(arg0, arg1, arg2, tbUrl)){
				aq.id(R.id.four_layout_list_item_imageview).clear();
			}else{
				aq.id(R.id.four_layout_list_item_imageview).image(tbUrl, true, true, 100, R.drawable.ic_launcher, null,0, 0);
			}
			
			return arg1;
		}
		
		
	}

  @Override
  public void onAttach(Activity activity) {
      super.onAttach(activity);

      // This makes sure that the container activity has implemented
      // the callback interface. If not, it throws an exception.
      try {
          mCallback = (box_Selection) activity;
      } catch (ClassCastException e) {
          throw new ClassCastException(activity.toString()
                  + " must implement OnHeadlineSelectedListener");
      }
  }




public void set_func(){
	//System.out.println("======order=====set_func===============");
	//Toast.makeText(getActivity(), String.valueOf("sp==null"+sp==null), 1000).show();
	 if (sp!=null) {
		 getActivity().runOnUiThread(new Runnable() {
				
				@Override
				public void run() {
					
					sp.setSelection(0,true);
					sp.invalidate();					
					// TODO Auto-generated method stub
			/*		Toast.makeText(getActivity(), "order set_func 1==="+sp.getSelectedItemPosition(), 1000).show();
					
					//sp.performItemClick(null, 0, 0);
					//sp.setAdapter(sp.getAdapter());
					sp.setSelection(2);
					 sp.requestLayout();
					//Toast.makeText(getActivity(), "order set_func 2==="+sp.getSelectedItemPosition(), 1000).show();
				*/
				
					
				}
			});
	}
		
		
	
}





@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
		long id) {
	// TODO Auto-generated method stub
	Toast.makeText(getActivity(), " o==="+position, 1000).show();
	if (position!=0) {		
		 mCallback.show_boxf(position);
		
		// Toast.makeText(getActivity(), "order onItemSelected ==="+sp.getSelectedItemPosition(), 1000).show();
	}
}






@Override
public void onNothingSelected(AdapterView<?> parent) {
	// TODO Auto-generated method stub
	
}


public void show_dialog(boolean b){
	
	if (dialog==null) {
		dialog = new ProgressDialog(getSupportActivity());
	    dialog.setIndeterminate(true);
	    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	    dialog.setMessage("post");
	}
	if (b) {
		dialog.show();
	}else{
		dialog.dismiss();
	} 
    
}


boolean is_check=true;
List<String> ids=new ArrayList<String>();
List<Box> ids_box=new ArrayList<Box>();


@Override
public void onClick(View v) {
	// TODO Auto-generated method stub
	switch (v.getId()) {  	
    case R.id.four_layout_btn_sure:
    	buy_sure();
    	break;
    case R.id.four_layout_address_select:
    	get_address();
    	break;
    case R.id.four_layout_btn_all:
    	btn_all();
    	break;
    case R.id.four_layout_btn_del:
    	btn_del();
    	break;
    case R.id.four_layout_list_item_check:
    final CheckBox ch=(CheckBox) v;	
	int pos=(Integer) ch.getTag();
	ch.setFocusable(false);
	ch.setFocusableInTouchMode(false);
	Box box=adap2.getList().get(pos);
	String id=box.getCollname()+"_"+box.getEntity().getId();
	if (ch.isChecked()) {
		
		if (!ids.contains(id)) {
			ids.add(id);
		}
		if (!ids_box.contains(box)) {
			ids_box.add(box);
		}
	}else{
		ids.remove(id);
		ids_box.remove(box);
	}

	Toast.makeText(getActivity(), id+" "+ids.size()+" "+ids_box.size(), 1000).show();
	break;	
    	
    default:  
        break;  
    }  
}



public void btn_all(){
	
	System.out.println("check_list.size()======="+check_list.size());
	for(final CheckBox checkb:check_list){
		int pos=(Integer) checkb.getTag();
		Box box=adap2.getList().get(pos);
		String id=box.getCollname()+"_"+box.getEntity().getId();
	
		
		if (is_check) {
			 getActivity().runOnUiThread(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					checkb.setChecked(true);
					//System.out.println("checkb.isChecked() ======="+checkb.isChecked());
				}
			});
			
			
			
			
			if (!ids.contains(id)) {
				ids.add(id);
			}
			if (!ids_box.contains(box)) {
				ids_box.add(box);
			}
			
		}else{
			 getActivity().runOnUiThread(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						checkb.setChecked(false);
						
					}
				});
						
			ids.remove(id);
			ids_box.remove(box);
		}
		
	}
if (is_check) {
		
		is_check=false;
	}else{
		is_check=true;
	}
System.out.println("ids======="+JSONObject.toJSONString(ids));
System.out.println("ids_box.size()======="+ids_box.size());
	
}

public void btn_del(){
	if (!ids.isEmpty()) {
		Map<String, Object> params = new HashMap<String, Object>();
	    params.put("type", 1);
	    params.put("ids", JSONObject.toJSONString(ids));
	  
	    System.out.println("btn_del ids===="+JSON.toJSONString(ids));
	    String url="http://"+Whm_app.api_url+":9000/api/buy_del_func";
	  AjaxCallback<String> cb = new AjaxCallback<String>();        
	  cb.url(url).type(String.class).weakHandler(FourFragmentOrder.this, "buy_del_func_result");

	  SharedPreferences sp=((Application)getActivity().getApplication()).getSharedPreferences("whm",Context.MODE_PRIVATE);
	String cookiename=sp.getString("cookie_name",null);
	String cookievalue=sp.getString("cookie_value",null);
	if (cookiename!=null&&cookievalue!=null) {
		cb.cookie(cookiename,cookievalue);               
	}else{
		
	}
	
	show_dialog(true);	
	cb.params(params);

	aq.ajax(cb);
	}else{
		
		
		Toast.makeText(getActivity(), "no selected", 1000).show();
	}
	
}

public void buy_del_func_result(String url, String r, AjaxStatus status){
	show_dialog(false);
	 if (status.getCode()==200) {
		 adap2.getList().removeAll(ids_box);
		
		// check_list.clear();
		 System.out.println("adap2.getList() "+JSONObject.toJSONString(adap2.getList()));
		 System.out.println("ids_box "+JSONObject.toJSONString(ids_box));
		 
		  getActivity().runOnUiThread(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					 
					 
				
					
					 num=0;
					 price=0;
					 for(Box b: adap2.getList()){
						  num=num+b.getNum();
						  price=price+b.getPrice();
						  
					  };
					
					 num_t.setText(String.valueOf(num));
					 price_t.setText(String.valueOf(price));
					 Toast.makeText(getActivity(), "adap2.getList().size()="+adap2.getList().size()+" num="+num+" price="+price, 3000).show();
					// adap2.notifyDataSetChanged();
					check_list.clear();
					ids.clear();
					ids_box.clear();
					adap2.notifyDataSetChanged();
					adap.notifyDataSetChanged();
					
				}
			});
		
		  
	 }else{
		 Toast.makeText(getActivity(), "parse error", 1000).show();
	 }
	
	
}







public void buy_sure(){
 
			// TODO Auto-generated method stub
			 show_dialog(true);
			int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
			View radioButton = radioButtonGroup.findViewById(radioButtonID);
			int idx = radioButtonGroup.indexOfChild(radioButton);
			
			  Map<String, Object> params = new HashMap<String, Object>();
			    params.put("type", idx+1);
			    params.put("tag", 1);
			    params.put("address_id", add.getId());
			  System.out.println("buy_sure===="+JSON.toJSONString(params));
			    
			String url="http://"+Whm_app.api_url+":9000/api/buy_sure_func";
			  AjaxCallback<String> cb = new AjaxCallback<String>();        
			  cb.url(url).type(String.class).weakHandler(this, "sure_func_result");
			  cb.params(params);
			  SharedPreferences sp=((Application)getActivity().getApplication()).getSharedPreferences("whm",Context.MODE_PRIVATE);
			String cookiename=sp.getString("cookie_name",null);
			String cookievalue=sp.getString("cookie_value",null);
			if (cookiename!=null&&cookievalue!=null) {
				cb.cookie(cookiename,cookievalue);               
			}
		    aq.ajax(cb);
		
	
	
}

public void sure_func_result(String url, String r, AjaxStatus status){
	  show_dialog(false);
	  //System.out.println("sure_func_result========="+r);
	//  System.out.println("sure_func_result status.getCode()========="+status.getCode());
	//  System.out.println("sure_func_result url========="+url);
	  if (status.getCode()==200) {
		
		 String re=JSON.parseObject(r).getString("result");
		 if (re.equals("ok")) {
		     refresh_list();
		}else if(re.equals("login_error")){
			
			Toast.makeText(getActivity(), String.valueOf("login error,please again"), 1000).show();
		}
		 
	 }else{		 
		 Toast.makeText(getActivity(), String.valueOf("post error,please again"), 1000).show();
	 }
}

public void refresh_list(){
	  getActivity().runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				 
				 num=0;
					price=0;
					 num_t.setText(String.valueOf(num));
					 price_t.setText(String.valueOf(price));
				 adap2.getList().clear();
				 adap2.notifyDataSetChanged();
				 adap.notifyDataSetChanged();
			
			}
		});
	
}

public void refresh(){
	show_dialog(true);
	init();
	
}

public void get_address(){
	
	  String url="http://"+Whm_app.api_url+":9000/api/user_address";
	  AjaxCallback<String> cb = new AjaxCallback<String>();        
	  cb.url(url).type(String.class).weakHandler(this, "get_address_ui");
	  SharedPreferences sp=((Application)getActivity().getApplication()).getSharedPreferences("whm",Context.MODE_PRIVATE);
	String cookiename=sp.getString("cookie_name",null);
	String cookievalue=sp.getString("cookie_value",null);
	if (cookiename!=null&&cookievalue!=null) {
		cb.cookie(cookiename,cookievalue);               
	}
	  aq.ajax(cb);
}
List<Address> adds;
AlertDialog dialog2;
public void get_address_ui(String url, String r, AjaxStatus status){
	
	  System.out.println("ui  s="+r); 
	  if (status.getCode()==200) {
		 
		  
		  final String s=r;
		  new Thread( new Runnable() {
			  @Override
			public void run() {
				  // String s1= JSON.parseObject(s).getString("users");
				  
				  String listj= JSON.parseObject(s).getString("list");
				  adds= JSON.parseArray(listj, Address.class);
				  
				  getActivity().runOnUiThread(new Runnable() {
					  
					  @Override
					  public void run() {
						
						  AlertDialog.Builder  b= new AlertDialog.Builder(getActivity());						 
						  b.setTitle("address select");
						
						  b.setAdapter(new adapter_address(adds),null);
						
						  dialog2=b.show();
						  
						  
					  }
				  });
			  }
		  }).start();
			
		  
	}else{
		Toast.makeText(getActivity(), "request error", 1000).show();
		
	}
	  
}




class adapter_address extends BaseAdapter{

	
	List<Address> list;
	public adapter_address() {
		super();
		// TODO Auto-generated constructor stub
	}
   
	
	
	public List<Address> getList() {
		return list;
	}



	public void setList(List<Address> list) {
		this.list = list;
	}



	public adapter_address(List<Address> list) {
		super();
		this.list = list;
	}


	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
	
		System.out.println("arg0---------------"+arg0);
		if(arg1 == null){
			arg1 = aq.inflate(arg1, R.layout.four_layout_address_list_item, arg2);
		}
		arg1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			    add=(Address)v.getTag();
				a.id(R.id.four_layout_contact_name).text(add.getContact_name());
				a.id(R.id.four_layout_contact_phone).text(add.getPhone());
				a.id(R.id.four_layout_contact_addr).text(add.getDetail_address());
				dialog2.dismiss();
			}
		});
		
		Address i = (Address) getItem(arg0);
		arg1.setTag(i);
		AQuery aq = aq2.recycle(arg1);	
		aq.id(R.id.four_layout_address_list_item_contact).text(i.getContact_name());
	    aq.id(R.id.four_layout_address_list_item_phone).text(i.getPhone());
	    aq.id(R.id.four_layout_address_list_item_address).text(i.getDetail_address());
	    
	//	aq.id(R.id.four_layout_address_list_item_radio).clicked(FourFragmentOrder.this);
		
		
	   // sp=(Spinner) aq.id(R.id.four_layout_list_spinner).getView();				
	//	sp.setSelection(0, true);
		//sp.setOnItemSelectedListener(FourFragmentOrder.this); 
		 /*v=(TextView) aq.id(R.id.four_layout_text_sp).getTextView();
		v.setText("order");
		v.setOnClickListener(FourFragmentOrder.this);*/
		//showListPopup(v);
	
		
	    
		
		return arg1;
	}
	
	
}






    
 
}
